package Spider;

import Spider.Model.WeatherInfo;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

import java.util.Map;

public class TestPipeline implements Pipeline {

    @Override
    public void process(ResultItems resultItems, Task task) {

        System.out.println("get page: " + resultItems.getRequest().getUrl());

        for (Map.Entry<String, Object> entry : resultItems.getAll().entrySet()) {
            System.out.println("======= 分析页面数据 =======");
            if (entry.getValue().getClass() == WeatherInfo.class){
                WeatherInfo w = (WeatherInfo) entry.getValue();
                System.out.println("当前时间 : " + w.getCurrentHour() + "点");
                System.out.println("云量信息 : " + w.getCurrentCloud());
                System.out.println("天气现象 : " + w.getCurrentWeather());
                System.out.println("气温信息 : " + w.getCurrentTemp() + "℃");
                System.out.println("气压信息 : " + w.getCurrentPress() + "毫米汞柱");
                System.out.println("湿度信息 : " + w.getCurrentHumidityCount() + "% -- " + w.getCurrentHumidityDesc());
                System.out.println("风向信息 : " + w.getWindSpeed() + "m/s -- " + w.getWindDesc());
            }

        }
    }
}
